<?php
/**
* DPMatchReserve copyright (c) 2008 sk89q
* @ http://digitalpaint.therisenrealm.com
* 
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*/

$base_dir = dirname(__FILE__);

if(!file_exists("./config.php"))
{
    echo "Error: It looks like that this application has not been properly installed. The configuration file is missing.";
    exit;
}

require "./config.php";
require "include/Smarty/Smarty.class.php";

if(count($CONFIG['servers']) == 0)
{
    echo "Error: It looks like that this application has not been properly installed. There are no servers configured.";
    exit;
}

if(!is_writable("cache"))
{
    echo "Error: It looks like that this application has not been properly installed. The cache directory cannot be written to.";
    exit;
}

// ===============================
// Configs
// ===============================

if(empty($CONFIG['base_url']))
{
    $CONFIG['base_url'] = 'http://'.$_SERVER['HTTP_HOST'].($_SERVER['SERVER_PORT'] != 80 ? ":{$_SERVER['SERVER_PORT']}" : '').dirname($_SERVER['SCRIPT_NAME']);
}

// ===============================
// Use Smarty for the templating engine
// ===============================

$smarty = new Smarty();

$smarty->debugging = $CONFIG['theme_debug_console'] ? true : false;
$smarty->compile_check = $CONFIG['theme_debug'] ? true : false;

$smarty->template_dir = "$base_dir/themes/{$CONFIG['theme']}";
$smarty->compile_dir = "$base_dir/cache/templates/compile";
$smarty->cache_dir = "$base_dir/cache/templates";
$smarty->config_dir = "$base_dir/themes/{$CONFIG['theme']}";

$smarty->assign('theme_url', "themes/{$CONFIG['theme']}");

function show_fatal_error($error)
{
    global $smarty;
    
    $smarty->assign('errors', array($error));
    $smarty->display('error.tpl');
    exit;
}
?>